import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class HourglassChess extends JFrame {
    private JButton labRedCheese = new JButton("  开始游戏  ");
    private JPanel setting = new JPanel();

    private JPanel cheeseBoard = new CheeseBoard();
    public HourglassChess() {
        setTitle("Hourglass Chess");
        JPanel root = new JPanel();
        root.setLayout(null);

        // 一个位置在(10,10)宽 400 高 70的名为状态的JPanel
        setting.setBorder(BorderFactory.createTitledBorder("状态"));
        setting.setLayout(new FlowLayout(FlowLayout.CENTER));
        setting.add(labRedCheese);
        setting.setBounds(10,10,400, 70);
        root.add(setting);

        // 一个位置在(10,90)宽400 高 530的名为棋盘的Jpanel
        cheeseBoard.setBorder(BorderFactory.createTitledBorder("棋盘"));
        cheeseBoard.setBackground(Color.white);
        cheeseBoard.setBounds(10,90,400, 530);
        cheeseBoard.setVisible(false);
        root.add(cheeseBoard);
        // JFrame中添加两个JPanel
        add(root);
        setSize(420, 660);
        setLocationRelativeTo(null);  // 居中显示
        setResizable(false);        // 禁止最大化
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 设置回调事件，如果点集的button中的文字是开始游戏 则棋盘可视
        labRedCheese.addActionListener(
            e -> {
                JButton btn = (JButton) e.getSource();
                if("  开始游戏  ".equals(btn.getText())) {
                    cheeseBoard.setVisible(true);
                    btn.setEnabled(false);
                }
            }
        );
    }

    public static void main(String[] args) {
        HourglassChess game = new HourglassChess();
        game.setVisible(true);
    }
}